<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <script src="https://cdn.jsdelivr.net/npm/vue@2.6.10/dist/vue.js"></script>
</head>

<body>
    <div id="app">
        <button @click="handler">修改对象数据</button>
        <li v-for="value,key in person" :key="item">{{key}}---{{value}}</li>
    </div>
    <script>
        Vue.config.productionTip = false;
        
        const vm = new Vue({
            el: "#app",
            data() {
                return {
                    person:{
                        name:"zhangsan",
                        age:18,
                        score:{
                            math:100,
                            chinese:90,
                        },
                    }
                }
            },
            methods: {
                handler(){
                    //1.可以直接修改对象的属性的值（层级没有限制）直接具有响应式
                    this.person.name = "lisi";
                    this.person.score.math = 110;
                    //2.重新赋值（具有响应式）
                    this.person={...this.person, age:22};

                    //3.新增属性(vm.$set&& Vue.set)（具有响应式）
                    this.$set(this.person,"sex","男");
                    Vue.set(this.person,"hobby","篮球");

                    //4.删除属性（vm.$delete && Vue.delete）（具有响应式）
                    // this.$delete(this.person,"age");
                    Vue.delete(this.person,"age");

                    //5.重新赋值（基本有响应式，代码不直观，麻烦）
                    delete this.person.age;
                    this.person={...this.person}

                }
            },
        })
</script>
</body>

</html>